package com.shwread.android.qysw.activity.healthy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shwread.android.qysw.step.UserStepModel;
import com.shwread.android.qysw.step.dto.DaysStepDto;
import com.shwread.android.qysw.step.model.UserHealthyDataModel;
import com.shwread.android.qysw.step.view.BarChartView;
import com.shwread.android.qysw.step.view.MyWeekStepBar;
import com.shwread.android.qysw.tools.TimeHelper;
import com.shwread.android.qysw10000227.R;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Fantasy on 16/4/4.
 */
public class HealthyDataActivity extends Activity {
    @InjectView(R.id.back_btn)
    ImageView backBtn;
    @InjectView(R.id.back_text)
    TextView backText;
    @InjectView(R.id.title_text)
    TextView titleText;
    @InjectView(R.id.right_text)
    TextView rightText;
    @InjectView(R.id.right_img)
    ImageView rightImg;
    @InjectView(R.id.today_step)
    TextView todayStep;
    @InjectView(R.id.today_distance)
    TextView todayDistance;
    @InjectView(R.id.today_calroise)
    TextView todayCalroise;

    @InjectView(R.id.now_month)
    TextView nowMonth;

    List<String> mSevenDayslist = new ArrayList();
    List<String> mMonthslist = new ArrayList();
    @InjectView(R.id.my_first_bar)
    BarChartView myFirstBar;
    @InjectView(R.id.my_sec_bar)
    MyWeekStepBar mySecBar;
    @InjectView(R.id.my_thi_bar)
    BarChartView myThiBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.healthy_data_new_activity);
        ButterKnife.inject(this);
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        DecimalFormat df = new DecimalFormat("#0.0");
        titleText.setText("健康数据");
        rightText.setText("数据汇总");
        rightText.setVisibility(View.VISIBLE);
        rightText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HealthyDataActivity.this, AllDatasActivity.class);
                startActivity(intent);
            }
        });
        todayDistance.setText(df.format(UserStepModel.getInstance().getUserTodayDistance()) + "KM");
        todayCalroise.setText(df.format(UserStepModel.getInstance().getUserTodayCalories()) + "大卡");
        nowMonth.setText(TimeHelper.getNowMonth() + "月");
        int todaySteps = UserStepModel.getInstance().getUserTodayStep();
        todayStep.setText(todaySteps + "步");

        TimeHelper.getToday();
        TimeHelper.getLastWeekDays();
        setSevenDays();
        setMonths();

        List<DaysStepDto> daysStepDtoList = UserHealthyDataModel.getInstance().getLastSevenDaysData();

        List<DaysStepDto> weekDaysStepDtoList = UserHealthyDataModel.getInstance().getLastFourWeekData();

        List<DaysStepDto> monthDaysStepDtoList = UserHealthyDataModel.getInstance().getYearData();

        for (int i = 0; i <= 11; i++) {
            Log.i("darreno", "hhhhh::" + i + ":" + monthDaysStepDtoList.get(i).getStep());
        }
        //List<DaysStepDto> daysStepDtoList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            DaysStepDto stepDto = new DaysStepDto();
            stepDto.setStep(0);
            daysStepDtoList.add(stepDto);
        }
        BarChartView.BarChartItemBean[] itemFris = new BarChartView.BarChartItemBean[]{
                new BarChartView.BarChartItemBean(mSevenDayslist.get(0), daysStepDtoList.get(0).getStep()),
                new BarChartView.BarChartItemBean(mSevenDayslist.get(1), daysStepDtoList.get(1).getStep()),
                new BarChartView.BarChartItemBean(mSevenDayslist.get(2), daysStepDtoList.get(2).getStep()),
                new BarChartView.BarChartItemBean(mSevenDayslist.get(3), daysStepDtoList.get(3).getStep()),
                new BarChartView.BarChartItemBean(mSevenDayslist.get(4), daysStepDtoList.get(4).getStep()),
                new BarChartView.BarChartItemBean(mSevenDayslist.get(5), daysStepDtoList.get(5).getStep()),
                new BarChartView.BarChartItemBean("今日", todaySteps),
        };
        myFirstBar.setItems(itemFris);

        MyWeekStepBar.BarChartItemBean[] itemSecs = new MyWeekStepBar.BarChartItemBean[]{
                new MyWeekStepBar.BarChartItemBean("第一周", weekDaysStepDtoList.get(3).getStep()),
                new MyWeekStepBar.BarChartItemBean("第二周", weekDaysStepDtoList.get(2).getStep()),
                new MyWeekStepBar.BarChartItemBean("第三周", weekDaysStepDtoList.get(1).getStep()),
                new MyWeekStepBar.BarChartItemBean("本周", (weekDaysStepDtoList.get(0).getStep())),
        };
        mySecBar.setItems(itemSecs);

        BarChartView.BarChartItemBean[] itemThis = new BarChartView.BarChartItemBean[]{
                new BarChartView.BarChartItemBean(mMonthslist.get(0), monthDaysStepDtoList.get((int) (Integer.valueOf(mMonthslist.get(0)) - 1)).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(1), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(1)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(2), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(2)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(3), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(3)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(4), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(4)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(5), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(5)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(6), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(6)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(7), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(7)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(8), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(8)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(9), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(9)) - 1).getStep()),
                new BarChartView.BarChartItemBean(mMonthslist.get(10), monthDaysStepDtoList.get(Integer.valueOf(mMonthslist.get(10)) - 1).getStep()),
                new BarChartView.BarChartItemBean("本月", monthDaysStepDtoList.get(TimeHelper.getNowMonth() - 1).getStep()),
        };
        myThiBar.setItems(itemThis);
    }

    public void setSevenDays() {
        mSevenDayslist = TimeHelper.getLastWeekDaysString();
    }

    public void setMonths() {
        mMonthslist = TimeHelper.getMonthsString(TimeHelper.getNowMonth());

    }
}
